#pragma once

#include "sensor_utils.hpp"

#include "muduo/net/Buffer.h"
#include "muduo/net/Channel.h"
#include "muduo/net/EventLoop.h"

#include <rclcpp/rclcpp.hpp>

#include <functional>

namespace sensor::radar {

using CanReceiveCallback = std::function<void(int frameid, muduo::net::Buffer&)>;

class CanTransreceiver {
public:
    CanTransreceiver(std::string dev, muduo::net::EventLoop* loop);

    void start();

    void filter();
    void filter(std::map<uint16_t, unsigned int> canIdMap);
    void send(int frameid, muduo::net::Buffer& buf);
    void setReceiveCallback(CanReceiveCallback cb);

private:
    void onDataReceived();

private:
    const std::string can_dev_;
    muduo::net::EventLoop* loop_;
    rclcpp::Logger logger_;
    std::unique_ptr<muduo::net::Channel> chnl_;
    sensor::utils::Signal<void(int frameid, muduo::net::Buffer&)> signal_;
    std::set<sensor::utils::Slot> slots_;
};

}